package com.wechat.back.controller;

import com.wechat.back.anno.OptLog;
import com.wechat.back.pojo.inform.Message;
import com.wechat.back.pojo.inform.MsgState;
import com.wechat.back.pojo.tools.Result;
import com.wechat.back.service.MsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/msg")
public class MsgController {
    @Autowired
    private MsgService msgService;
    //查询所有消息
    @GetMapping("/list")
    public Result<List<Message>> list(){
        List<Message> msg = msgService.findAll();
        return Result.success(msg);
    }
    //通过消息标识查询用户的所有消息
    @GetMapping("/listBySign")
    public Result<List<Message>> listBySign(Integer msgSign){
        List<Message> msgList = msgService.findBySign(msgSign);
        return Result.success(msgList);
    }
    //添加消息
    @OptLog(optModule = "消息模块",optType = "添加", optDesc = "添加消息")
    @PostMapping("/add")
    public Result add(@RequestBody @Validated(Message.Add.class) Message message){
        msgService.addMsg(message);
        return Result.success("添加成功");
    }
    //查询消息列表
    @GetMapping("/listMsgStateByUserId")
    public Result<MsgState> listMsgStateByUserId(Integer userId){
        MsgState msgState = msgService.findMsgStateByUserId(userId);
        return Result.success(msgState);
    }
    //添加发送消息的人
    @OptLog(optModule = "消息模块",optType = "添加", optDesc = "添加发送消息的人")
    @PostMapping("/addMsgState")
    public Result addMsgState(){
        msgService.addMsgState();
        return Result.success("添加成功");
    }
    //查询发送消息的用户列表
    @GetMapping("/listMsgState")
    public Result<List<MsgState>> findAllMsgState(@RequestParam(required = false) String user){
        List<MsgState> msgState = msgService.findAllMsgState(user);
        return Result.success(msgState);
    }
}
